<!-- 自定义标准图表 设置百分百宽度 通过平台组件来适配尺寸 可以替换数据以及设置高级属性自定义扩展 详细查看组件示例.txt
  注:如需设置图片存放文件夹名称需应与当前文件名一致(1并在aircim.webpack.build.component.config.js配置需要打包的文件 2.npm run lib_c 执行打包命令  最后的组件会打包在components/grids中)-->
<template>
  <div class="scale-box" :id="dynamicIdName()">
    <div
      class="business-efficiency-box animate__animated"
      :class="dynamicClassName"
      style="width: 460px;height: 269px;"
      :id="dynamicChildName()"
    >
      <h1 class="h1_title">
        <span>办理效率</span>
      </h1>
      <div class="window-num">
        <span class="window-num-text">办件办理平均用时</span>
        <ScrollNumber :value="windownum" class="stock-price"></ScrollNumber
        ><span class="unit">min</span>
      </div>
      <div class="sp-wrap">
        <div class="sp-wrap-item">
          <p class="sp-wrap-item-name">
            <span>审批通过率</span><span class="num"><em>97.84</em>%</span>
          </p>
          <p class="per-wrap"><i style="width: 50%;"></i></p>
        </div>
        <div class="sp-wrap-item">
          <p class="sp-wrap-item-name">
            <span>按时办结率</span><span class="num"><em>97.84</em>%</span>
          </p>
          <p class="per-wrap"><i style="width: 50%;"></i></p>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
//引入封装方法
import encapsulation from "../../utils/aircimGird";
import ScrollNumber from "./ScrollNumber.vue";
export default {
  //混入封装方法
  mixins: [encapsulation],
  components: {
    ScrollNumber,
  },
  data: function() {
    return {
      windownum: "15.28",
      resizeObserver: null,
      //动态Id
      timestamp: null,
    };
  },
  mounted() {
    this.timestamp = new Date().getTime();
    this.$nextTick(() => {
      // 监听盒子变化
      this.listenChangeFn();
    });
  },
  methods: {
    //监听外部盒子的大小 然后对数据井行缩放
    scaleFn() {
      const parentBox = document.getElementById(`dynamic-${this.timestamp}`);
      const childBox = document.getElementById(
        `dynamicChild-${this.timestamp}`
      );
      const parentWidth = parentBox.offsetWidth;
      const parentHeight = parentBox.offsetHeight;
      const childWidth = childBox.offsetWidth;
      const childHeight = childBox.offsetHeight;
      let scaleX, scaleY;
      if (parentWidth < childWidth || parentHeight < childHeight) {
        const scaleBasedOnWidth = parentWidth / childWidth;
        const scaleBasedOnHeight = parentHeight / childHeight;
        scaleX = scaleBasedOnWidth;
        scaleY = scaleBasedOnHeight;
      } else {
        scaleX = parentWidth / childWidth;
        scaleY = parentHeight / childHeight;
      }
      childBox.style.transform = `scale(${scaleX}, ${scaleY})`;
    },
    // 监听盒子变化
    listenChangeFn() {
      let that = this;
      const element = document.getElementById(`dynamic-${this.timestamp}`);
      // console.log(element, "element");
      if (element) {
        new ResizeObserver(() => {
          // 处理元素大小变化的逻辑
          that.scaleFn();
        }).observe(element);
      }
    },
    // 绑定动画样式 animate__flash
    bindAnimationFn(animateName) {
      if (animateName != null) {
        this.dynamicClassName = animateName;
      }
    },
    //定义唯一ID名
    dynamicIdName() {
      return `dynamic-${this.timestamp}`;
    },
    //定义唯一ID名
    dynamicChildName() {
      return `dynamicChild-${this.timestamp}`;
    },
  },
  // 销毁监听
  beforeDestroy() {
    // 组件销毁前停止监听
    if (this.resizeObserver) {
      this.resizeObserver.disconnect();
    }
    if (this.requestTime != null) {
      clearInterval(this.requestTime);
    }
  },
};
</script>
<style lang="scss" scoped>
@import "../../static/assets/common.scss";
</style>
<style lang="scss" scoped>
.scale-box {
  width: 100%;
  height: 100%;
}

.business-efficiency-box {
  position: absolute;
  padding: 0 20px;
  box-sizing: border-box;
  overflow: hidden;
  transform-origin: left top;
  background-image: url(../../../thumbnail/backImg/new-border-mini-green.png);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  color: #fff;
}
// 窗口运行
.window-num {
  margin-bottom: 23px;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 76px;
  background: url(../../static/assets/HallSituation/window_mocule_bg.png)
    no-repeat center center;
  background-size: 100% 100%;

  .window-num-text {
    padding-right: 10px;
    min-width: 106px;
    font-size: 16px;
    font-weight: 700;
  }

  .unit {
    color: rgba(150, 190, 224, 0.8);
    margin-left: 16px;
    font-size: 14px;
  }
}
.sp-wrap {
  display: flex;
  justify-content: space-between;
  .sp-wrap-item {
    padding: 14px 16px;
    width: calc(50% - 14px);
    height: 78px;
    background: url(../../static/assets/BusinessEfficiency/spbg.png) no-repeat
      center center;
    background-size: 100% 100%;
    .sp-wrap-item-name {
      display: flex;
      justify-content: space-between;
      line-height: 24px;
      height: 24px;
    }
    .per-wrap {
      margin-top: 14px;
      display: flex;
      border: 1px solid #43f4ff;
      height: 10px;
      border-radius: 10px;
      i {
        height: 100%;
        border-radius: 30px;
        background: linear-gradient(
          90deg,
          #00cedb 0%,
          #72ffaa 94.5%,
          #fff 100%
        );
        box-shadow: 0px 0px 8px 1px rgba(0, 255, 240, 0.65);
      }
    }
  }
}
</style>
